```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据库约束设计指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f9fafb;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .text-primary {
            color: #4f46e5;
        }
        .bg-primary {
            background-color: #4f46e5;
        }
        .border-primary {
            border-color: #4f46e5;
        }
        .hover\:bg-primary:hover {
            background-color: #4338ca;
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.25rem;
            position: relative;
        }
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
            background-color: #4f46e5;
            border-radius: 0.5rem 0 0 0.5rem;
        }
        .feature-card {
            transition: all 0.3s ease;
            border-radius: 0.5rem;
            overflow: hidden;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 0.8;
            margin: 0.1em 0.15em 0 0;
            color: #4f46e5;
            font-weight: 700;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <header class="bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-7xl mx-auto text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6">数据库约束设计权威指南</h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto mb-8">掌握约束的艺术，守护数据完整性</p>
            <div class="flex justify-center space-x-4">
                <a href="#importance" class="bg-white text-indigo-600 px-6 py-3 rounded-lg font-medium hover:bg-gray-100 transition duration-300">
                    <i class="fas fa-shield-alt mr-2"></i>开始学习
                </a>
                <a href="#best-practices" class="border-2 border-white text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:text-indigo-600 transition duration-300">
                    <i class="fas fa-star mr-2"></i>最佳实践
                </a>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Importance Section -->
        <section id="importance" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-shield-alt text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">一、约束的重要性：数据完整性的守护者</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <div class="mb-6 rounded-xl overflow-hidden shadow-lg">
                        <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1742041551169-17c99d8c-989d-43ea-b2f6-d92bd5511109.png" alt="数据库约束" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <p class="text-lg text-gray-700 mb-6 drop-cap">想象一下，如果没有约束，数据库会变成什么样：</p>
                    <ul class="space-y-3 mb-8">
                        <li class="flex items-start">
                            <div class="bg-red-100 text-red-700 rounded-full p-1 mr-3 mt-1">
                                <i class="fas fa-times text-xs"></i>
                            </div>
                            <span class="text-gray-700">用户表出现重复ID</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-red-100 text-red-700 rounded-full p-1 mr-3 mt-1">
                                <i class="fas fa-times text-xs"></i>
                            </div>
                            <span class="text-gray-700">订单金额为负数</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-red-100 text-red-700 rounded-full p-1 mr-3 mt-1">
                                <i class="fas fa-times text-xs"></i>
                            </div>
                            <span class="text-gray-700">商品库存超过上限</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-red-100 text-red-700 rounded-full p-1 mr-3 mt-1">
                                <i class="fas fa-times text-xs"></i>
                            </div>
                            <span class="text-gray-700">外键关联数据丢失</span>
                        </li>
                    </ul>
                    
                    <p class="text-lg text-gray-700 mb-4">通过合理的表约束设计，我们可以：</p>
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div class="bg-green-50 border border-green-200 rounded-lg p-4 flex items-start">
                            <div class="bg-green-100 text-green-700 rounded-full p-1 mr-3">
                                <i class="fas fa-check text-sm"></i>
                            </div>
                            <span class="text-gray-700">保证数据一致性</span>
                        </div>
                        <div class="bg-green-50 border border-green-200 rounded-lg p-4 flex items-start">
                            <div class="bg-green-100 text-green-700 rounded-full p-1 mr-3">
                                <i class="fas fa-check text-sm"></i>
                            </div>
                            <span class="text-gray-700">防止脏数据入库</span>
                        </div>
                        <div class="bg-green-50 border border-green-200 rounded-lg p-4 flex items-start">
                            <div class="bg-green-100 text-green-700 rounded-full p-1 mr-3">
                                <i class="fas fa-check text-sm"></i>
                            </div>
                            <span class="text-gray-700">提高查询性能</span>
                        </div>
                        <div class="bg-green-50 border border-green-200 rounded-lg p-4 flex items-start">
                            <div class="bg-green-100 text-green-700 rounded-full p-1 mr-3">
                                <i class="fas fa-check text-sm"></i>
                            </div>
                            <span class="text-gray-700">简化应用层校验逻辑</span>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Basic Constraints Section -->
        <section id="basic-constraints" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-lock text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">二、基础约束：数据完整性的第一道防线</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- Primary Key -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-indigo-100 text-indigo-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-key text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">2.1 主键约束（Primary Key）</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL
);</code></pre>
                        </div>
                        <div class="space-y-2">
                            <h4 class="font-medium text-gray-700">特性：</h4>
                            <ul class="text-gray-600 space-y-1">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span>唯一性</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span>非空</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span>自动创建索引</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Unique Key -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-purple-100 text-purple-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-unlock-alt text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">2.2 唯一约束（Unique Key）</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">ALTER TABLE users 
ADD UNIQUE (username);</code></pre>
                        </div>
                        <div class="space-y-2">
                            <h4 class="font-medium text-gray-700">应用场景：</h4>
                            <ul class="text-gray-600 space-y-1">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-1 mr-2"></i>
                                    <span>用户名唯一</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-1 mr-2"></i>
                                    <span>手机号唯一</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-1 mr-2"></i>
                                    <span>邮箱唯一</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- NOT NULL -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-pink-100 text-pink-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-ban text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">2.3 非空约束（NOT NULL）</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE orders (
    id INT PRIMARY KEY,
    user_id INT NOT NULL,
    amount DECIMAL(10,2) NOT NULL
);</code></pre>
                        </div>
                        <p class="text-gray-600">确保关键字段必须有值，避免NULL值带来的不确定性。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Advanced Constraints Section -->
        <section id="advanced-constraints" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-shield-virus text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">三、高级约束：数据完整性的终极守护</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- Foreign Key -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-blue-100 text-blue-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-link text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">3.1 外键约束（Foreign Key）</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE orders (
    id INT PRIMARY KEY,
    user_id INT,
    FOREIGN KEY (user_id) 
    REFERENCES users(id)
    ON DELETE CASCADE
    ON UPDATE CASCADE
);</code></pre>
                        </div>
                        <div class="space-y-2">
                            <h4 class="font-medium text-gray-700">级联操作：</h4>
                            <ul class="text-gray-600 space-y-1">
                                <li class="flex items-start">
                                    <i class="fas fa-long-arrow-alt-right text-xs text-blue-500 mt-1 mr-2"></i>
                                    <span><strong>CASCADE</strong>：主表删除/更新，子表同步</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-long-arrow-alt-right text-xs text-blue-500 mt-1 mr-2"></i>
                                    <span><strong>SET NULL</strong>：主表删除/更新，子表置空</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-long-arrow-alt-right text-xs text-blue-500 mt-1 mr-2"></i>
                                    <span><strong>RESTRICT</strong>：禁止主表删除/更新</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Check Constraint -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-teal-100 text-teal-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-check-double text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">3.2 检查约束（Check）</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE products (
    id INT PRIMARY KEY,
    price DECIMAL(10,2) 
        CHECK (price > 0),
    stock INT 
        CHECK (stock >= 0)
);</code></pre>
                        </div>
                        <p class="text-gray-600">定义业务规则，确保数据符合特定条件，如价格必须大于0，库存不能为负。</p>
                    </div>
                </div>

                <!-- Default Constraint -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-amber-100 text-amber-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-clock text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">3.3 默认值约束（Default）</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE logs (
    id INT PRIMARY KEY,
    create_time DATETIME 
        DEFAULT CURRENT_TIMESTAMP,
    status ENUM('active','inactive') 
        DEFAULT 'active'
);</code></pre>
                        </div>
                        <p class="text-gray-600">为字段提供默认值，简化插入操作并确保字段始终有值。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Practical Case Section -->
        <section id="practical-case" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-shopping-cart text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">四、实战案例：电商系统约束设计</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- Users Table -->
                <div class="col-span-1">
                    <div class="bg-white shadow-md rounded-lg overflow-hidden">
                        <div class="bg-indigo-600 text-white px-6 py-3">
                            <h3 class="font-bold">4.1 用户表设计</h3>
                        </div>
                        <div class="p-6">
                            <div class="code-block">
                                <pre><code class="text-xs">CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR(100) NOT NULL UNIQUE,
    phone CHAR(11) NOT NULL UNIQUE,
    password_hash CHAR(64) NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP 
                ON UPDATE CURRENT_TIMESTAMP
);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Products Table -->
                <div class="col-span-1">
                    <div class="bg-white shadow-md rounded-lg overflow-hidden">
                        <div class="bg-green-600 text-white px-6 py-3">
                            <h3 class="font-bold">4.2 商品表设计</h3>
                        </div>
                        <div class="p-6">
                            <div class="code-block">
                                <pre><code class="text-xs">CREATE TABLE products (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(200) NOT NULL,
    price DECIMAL(10,2) NOT NULL 
        CHECK (price > 0),
    stock INT NOT NULL 
        CHECK (stock >= 0),
    category_id INT NOT NULL,
    FOREIGN KEY (category_id) 
    REFERENCES categories(id)
);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Orders Table -->
                <div class="col-span-1">
                    <div class="bg-white shadow-md rounded-lg overflow-hidden">
                        <div class="bg-purple-600 text-white px-6 py-3">
                            <h3 class="font-bold">4.3 订单表设计</h3>
                        </div>
                        <div class="p-6">
                            <div class="code-block">
                                <pre><code class="text-xs">CREATE TABLE orders (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    total_amount DECIMAL(10,2) NOT NULL 
        CHECK (total_amount > 0),
    status ENUM('pending','paid','shipped','completed') 
           DEFAULT 'pending',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) 
    REFERENCES users(id)
);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Optimization Section -->
        <section id="optimization" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-tachometer-alt text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">五、约束优化：性能与完整性的平衡</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- Index Optimization -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-yellow-100 text-yellow-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-search text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">5.1 索引优化</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">-- 复合唯一约束
ALTER TABLE order_items 
ADD UNIQUE (order_id, product_id);

-- 外键索引
CREATE INDEX idx_user_id 
ON orders (user_id);</code></pre>
                        </div>
                        <p class="text-gray-600">合理添加索引提高查询性能，但要注意写操作的性能影响。</p>
                    </div>
                </div>

                <!-- Partitioning -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-orange-100 text-orange-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-database text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">5.2 分区表约束</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE logs (
    id INT AUTO_INCREMENT,
    log_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    content TEXT,
    PRIMARY KEY (id, log_time)
) PARTITION BY RANGE (YEAR(log_time)) (
    PARTITION p2022 VALUES LESS THAN (2023),
    PARTITION p2023 VALUES LESS THAN (2024)
);</code></pre>
                        </div>
                        <p class="text-gray-600">分区表需要特别注意主键和约束的设计。</p>
                    </div>
                </div>

                <!-- Triggers -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-red-100 text-red-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-exclamation-triangle text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">5.3 触发器补充约束</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">DELIMITER //
CREATE TRIGGER before_order_insert
BEFORE INSERT ON orders
FOR EACH ROW
BEGIN
    IF NEW.total_amount <= 0 THEN
        SIGNAL SQLSTATE '45000' 
        SET MESSAGE_TEXT = '订单金额必须大于0';
    END IF;
END//
DELIMITER ;</code></pre>
                        </div>
                        <p class="text-gray-600">当约束逻辑复杂时，可使用触发器实现。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- MySQL 8.0 Features -->
        <section id="mysql-features" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-bolt text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">六、MySQL 8.0新特性：约束的进化</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- Functional Indexes -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-indigo-100 text-indigo-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-function text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">6.1 函数索引</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE users (
    id INT PRIMARY KEY,
    email VARCHAR(100),
    INDEX idx_lower_email ((LOWER(email)))
);</code></pre>
                        </div>
                        <p class="text-gray-600">支持在函数结果上创建索引，扩展了约束能力。</p>
                    </div>
                </div>

                <!-- Invisible Indexes -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-purple-100 text-purple-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-eye-slash text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">6.2 不可见索引</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">ALTER TABLE users 
ADD UNIQUE INDEX idx_phone (phone) 
INVISIBLE;</code></pre>
                        </div>
                        <p class="text-gray-600">可以创建暂时不使用的索引，不影响查询优化器。</p>
                    </div>
                </div>

                <!-- Expression Defaults -->
                <div class="feature-card bg-white shadow-md hover:shadow-xl">
                    <div class="p-6">
                        <div class="bg-pink-100 text-pink-700 rounded-full w-12 h-12 flex items-center justify-center mb-4">
                            <i class="fas fa-calculator text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800 mb-3">6.3 表达式默认值</h3>
                        <div class="code-block mb-4">
                            <pre><code class="text-sm">CREATE TABLE orders (
    id INT PRIMARY KEY,
    create_time DATETIME 
    DEFAULT (NOW() + INTERVAL 8 HOUR)
);</code></pre>
                        </div>
                        <p class="text-gray-600">支持更复杂的默认值表达式。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices Section -->
        <section id="best-practices" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-medal text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">七、约束设计最佳实践</h2>
            </div>

            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-12">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-bold text-gray-800 mb-4">命名规范</h3>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <div class="bg-gray-100 text-gray-700 rounded-full p-1 mr-3 mt-1">
                                        <i class="fas fa-key text-xs"></i>
                                    </div>
                                    <span class="text-gray-700"><strong>主键</strong>：<code>pk_表名</code></span>
                                </li>
                                <li class="flex items-start">
                                    <div class="bg-gray-100 text-gray-700 rounded-full p-1 mr-3 mt-1">
                                        <i class="fas fa-unlock text-xs"></i>
                                    </div>
                                    <span class="text-gray-700"><strong>唯一键</strong>：<code>uk_表名_字段名</code></span>
                                </li>
                                <li class="flex items-start">
                                    <div class="bg-gray-100 text-gray-700 rounded-full p-1 mr-3 mt-1">
                                        <i class="fas fa-link text-xs"></i>
                                    </div>
                                    <span class="text-gray-700"><strong>外键</strong>：<code>fk_子表_父表</code></span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h3 class="text-xl font-bold text-gray-800 mb-4">约束顺序</h3>
                            <ol class="space-y-3 list-decimal list-inside text-gray-700">
                                <li>先定义主键</li>
                                <li>再定义唯一约束</li>
                                <li>最后定义外键</li>
                            </ol>
                        </div>
                    </div>

                    <div class="mt-8">
                        <h3 class="text-xl font-bold text-gray-800 mb-4">性能考量</h3>
                        <div class="grid md:grid-cols-3 gap-4">
                            <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
                                <h4 class="font-medium text-blue-700 mb-2">外键约束</h4>
                                <p class="text-sm text-gray-600">避免过多外键影响写性能</p>
                            </div>
                            <div class="bg-green-50 border border-green-200 rounded-lg p-4">
                                <h4 class="font-medium text-green-700 mb-2">检查约束</h4>
                                <p class="text-sm text-gray-600">大表慎用检查约束</p>
                            </div>
                            <div class="bg-purple-50 border border-purple-200 rounded-lg p-4">
                                <h4 class="font-medium text-purple-700 mb-2">触发器</h4>
                                <p class="text-sm text-gray-600">合理使用触发器</p>
                            </div>
                        </div>
                    </div>

                    <div class="mt-8">
                        <h3 class="text-xl font-bold text-gray-800 mb-4">文档记录</h3>
                        <div class="code-block">
                            <pre><code class="text-sm">-- 查看表约束
SELECT * FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_NAME = 'orders';</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Intelligent Constraints Section -->
        <section id="intelligent-constraints" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-brain text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">八、智能约束管理</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-8 flex flex-col items-center text-center">
                    <div class="bg-indigo-100 text-indigo-700 rounded-full w-16 h-16 flex items-center justify-center mb-4">
                        <i class="fas fa-cogs text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">动态约束</h3>
                    <p class="text-gray-600">根据业务规则自动调整约束条件</p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-8 flex flex-col items-center text-center">
                    <div class="bg-purple-100 text-purple-700 rounded-full w-16 h-16 flex items-center justify-center mb-4">
                        <i class="fas fa-robot text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">AI优化</h3>
                    <p class="text-gray-600">智能推荐最优约束组合</p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-8 flex flex-col items-center text-center">
                    <div class="bg-blue-100 text-blue-700 rounded-full w-16 h-16 flex items-center justify-center mb-4">
                        <i class="fas fa-cloud text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">云原生支持</h3>
                    <p class="text-gray-600">分布式环境下的约束一致性</p>
                </div>
            </div>
        </section>

        <!-- Concept Map -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="bg-primary w-12 h-12 rounded-full flex items-center justify-center text-white mr-4">
                    <i class="fas fa-project-diagram text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">数据库约束概念关系图</h2>
            </div>
            <div class="bg-white rounded-xl shadow-lg p-8">
                <div class="mermaid">
                    graph TD
                        A[数据库约束] --> B[基础约束]
                        A --> C[高级约束]
                        A --> D[智能约束]
                        
                        B --> B1[主键约束]
                        B --> B2[唯一约束]
                        B --> B3[非空约束]
                        
                        C --> C1[外键约束]
                        C --> C2[检查约束]
                        C --> C3[默认值约束]
                        
                        D --> D1[动态约束]
                        D --> D2[AI优化]
                        D --> D3[云原生支持]
                        
                        B1 --> E[唯一性]
                        B1 --> F[非空]
                        B1 --> G[自动索引]
                        
                        C1 --> H[级联操作]
                        C1 --> I[数据一致性]
                        
                        C2 --> J[业务规则]
                        C2 --> K[数据验证]
                        
                        D1 --> L[自动调整]
                        D2 --> M[智能推荐]
                        D3 --> N[分布式一致性]
                        
                        style A fill:#4f46e5,color:white
                        style B fill:#7c3aed,color:white
                        style C fill:#a855f7,color:white
                        style D fill:#d946ef,color:white
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-7xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fas fa-link mr-2"></i>www.yuque.com/jtostring
                    </a>
                </div>
                <div class="flex space-x-6">
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```